namespace OneWorks.Utils.FluentData
{
    internal abstract class BaseInsertBuilder
    {
        public BuilderData Data { get; set; }
        protected ActionsHandler Actions { get; set; }

        protected BaseInsertBuilder(IDbCommand command, string name)
        {
            this.Data =  new BuilderData(command, name);
            this.Actions = new ActionsHandler(this.Data);
        }

        private IDbCommand GetPreparedCommand()
        {
            this.Data.Command.ClearSql.Sql(this.Data.Command.Data.Context.Data.Provider.GetSqlForInsertBuilder(this.Data));
            return this.Data.Command;
        }

        public int Execute()
        {
            return this.GetPreparedCommand().Execute();
        }

        public T ExecuteReturnLastId<T>(string identityColumnName = null)
        {
            return this.GetPreparedCommand().ExecuteReturnLastId<T>(identityColumnName);
        }
    }
}